/**
 * This is gulp task main file,  check system environment， then define some task for auto setup , build, deploy
 * @Author: jiangcheng198745@hotmail.com
 * Date: 2016/07/25
 */
'use strict';

import {log, colors}  from 'gulp-util';
import semver from 'semver';

// check nodejs version
if (!semver.satisfies(process.version, '>=4')) {
    log(colors.red("Nodejs version should be at least version 4.x, current is:"), colors.red.bold(process.version));
    log(colors.red('Consider use nvm: http://github.com/creationix/nvm'));
    process.exit(1);
}

// check npm version
import {sync as spawn} from 'cross-spawn';

let child = spawn('npm', ['--version']);
let npmVersion = child.stdout ? child.stdout.toString() : '';

if (child.status !== 0 || !semver.satisfies(npmVersion, '=2')) {
    log(colors.red("npm version should strictly be version 2.x, current is:"), colors.red.bold(npmVersion));
    log(colors.red('npm install -g npm@latest-2 may do the trick'));
    process.exit(1);
}

// gulpfile.js, use es2015 , file name should been named as gulpfile.babel.js
import gulp from 'gulp';
import taskListing from 'gulp-task-listing';
import requireDir from 'require-dir';


// load task from gulp directory
// Tasks are imported from the 'gulp' directory
requireDir('./gulp', {
  recurse: true
});

// default task, show all task list
gulp.task('default',['help']);

// help task
gulp.task('help', taskListing);
